using System;
using System.Drawing;
using System.Windows.Forms;

namespace PopLava.Tools
{
    /// <summary>
    /// Tiles
    /// </summary>
    public class TileControl : Control
    {
        Image _image;
        private string g_sViewId = String.Empty;
        private int g_iZIndex;
        private Font g_fFont;
        private bool g_IsTileLocked = false;
        private bool g_bIsAvailable = true;

        public TileControl()
        {
            // Allow transparent background
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.Font = g_fFont;
            this.Cursor = System.Windows.Forms.Cursors.Hand;
            this.AllowDrop = true;
        }
        public Image Image
        {
            get
            {
                return _image;
            }
            set
            {
                _image = value;
            }
        }
        public bool IsAvailable
        {
            get
            {
                return g_bIsAvailable;
            }
            set
            {
                g_bIsAvailable = value;
            }
        }
        public string ViewId
        {
            get
            {
                return g_sViewId;
            }
            set
            {
                g_sViewId = value;
            }
        }
        public int ZIndex
        {
            get
            {
                return g_iZIndex;
            }
            set
            {
                g_iZIndex = value;
            }
        }
        public Font FontObj
        {
            get
            {
                return g_fFont;
            }
            set
            {
                g_fFont = value;
            }
        }
        public bool IsTileLocked
        {
            get
            {
                return g_IsTileLocked;
            }
            set
            {
                g_IsTileLocked = value;
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            // Draw image, sized to control
            if (this.Image != null)
            {
                int iExtraWidth = this.Width / 100;
                int iExtraHeight = this.Height / 100;
                e.Graphics.DrawImage(this.Image, 0, 0, this.Width + iExtraWidth, this.Height + iExtraHeight);
            }
            // Draw text, centered vertically and horizontally
            RectangleF rectangle = new RectangleF(0, 0, this.Width, this.Height);
            StringFormat format = new StringFormat();
            format.LineAlignment = StringAlignment.Center;
            format.Alignment = StringAlignment.Center;
            System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(this.ForeColor);
            e.Graphics.DrawString(this.Text, this.Font, drawBrush, rectangle, format);
        }
    }
}
